//
//  CustomTitleView.swift
//  DragonWallet
//
//  Created by volantPig on 2024/4/8.
//

import UIKit

protocol CustomTitleViewDelegate {
    func customTitleDidSelected(at index: Int)
}

// 177 * 30
class CustomTitleView: UIView {
    
    var myDelegate: CustomTitleViewDelegate?
    var leftButton = UIButton(type: .custom)
    var rightButton = UIButton(type: .custom)
    var bottomLine = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupUIElements()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUIElements() {
        self.addSubview(self.leftButton)
        self.leftButton.frame = CGRect(x: 0, y: 0, width: 67, height: 44)
        
        self.leftButton.setTitle("跨境直邮", for: .normal)
        self.leftButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
        self.leftButton.setTitleColor(color("#333333"), for: .normal)
        self.leftButton.addTarget(self, action: #selector(leftButtonAction), for: .touchUpInside)
        
        self.addSubview(self.rightButton)
        self.rightButton.frame = CGRect(x: 110, y: 0, width: 67, height: 44)
        self.rightButton.setTitle("境外预售", for: .normal)
        self.rightButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.rightButton.setTitleColor(color("#333333"), for: .normal)
        self.rightButton.addTarget(self, action: #selector(rightButtonAction), for: .touchUpInside)
        
        self.addSubview(self.bottomLine)
//        177 30
        self.bottomLine.frame = CGRect(x: 21, y: 41, width: 25, height: 3)
        self.bottomLine.backgroundColor = color("#FA6161")
    }
    
    @objc func leftButtonAction() {
        self.leftButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
        self.rightButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.bottomLine.frame = CGRect(x: 21, y: 41, width: 25, height: 3)
        self.myDelegate?.customTitleDidSelected(at: 0)
    }
    
    @objc func rightButtonAction() {
        
        self.leftButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.rightButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
        self.bottomLine.frame = CGRect(x: 131, y: 41, width: 25, height: 3)
        self.myDelegate?.customTitleDidSelected(at: 1)
    }
    
    

}
